﻿var bigPosition = $("#BigPosition"), smallPosition = $("#SmallPosition");
var province = $("#Provincial"), city = $("#Municipal");
for (var i = 0; i < bigPositionList.length; i++) {
    addEle(bigPosition, bigPositionList[i].name);
}
for (var i = 0; i < provinceList.length; i++) {
    addEle(province, provinceList[i].name);
}
function addEle(ele, value) {
    var optionStr = "";
    optionStr = "<option value=" + value + ">" + value + "</option>";
    ele.append(optionStr);
}
function removeEle(ele) {
    ele.find("option").remove();
    var optionStar = "<option value=" + "请选择" + ">" + "请选择" + "</option>";
    ele.append(optionStar);
}
var provinceText, bigPositionText;
bigPosition.on("change", function () {
    bigPositionText = $(this).val();
    $.each(bigPositionList, function (i, item) {
        if (bigPositionText == item.name) {
            cityItem = i;
            return cityItem
        }
    });
    removeEle(smallPosition);
    $.each(bigPositionList[cityItem].smallPositionList, function (i, item) {
        addEle(smallPosition, item.name)
    });
});
province.on("change", function () {
    provinceText = $(this).val();
    $.each(provinceList, function (i, item) {
        if (provinceText == item.name) {
            cityItem = i;
            return cityItem
        }
    });
    removeEle(city);
    $.each(provinceList[cityItem].cityList, function (i, item) {
        addEle(city, item.name)
    });
});